package com.bwie.es.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.common.domain.Shop;
import com.bwie.common.domain.request.ShopRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.es.service.EsShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@RequestMapping("/shop")
public class EsShopController {

    @Autowired
    private EsShopService esShopService;

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/searchBook")
    public Result<PageResult<Shop>> search(@RequestBody ShopRequest shopRequest){
        log.info("功能名称：文章搜索，请求URI：{}，请求方式：{}，请求参数：{}",
                request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(shopRequest));
        Result<PageResult<Shop>> search = esShopService.search(shopRequest);
        log.info("功能名称：文章搜索，请求URI：{}，请求方式：{}，响应结果：{}",
                request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(shopRequest));
        return search;
    }

}
